/* function add(a,b){
    return a+b;
}
function sub(a,b){
    return a-b;
}
function mul(a,b){
    return a*b;
}
function del(a,b){
    return a/b;
}
console.log(add(10,20));
console.log(sub(10,20));
console.log(mul(10,20));
console.log(del(10,20)); */
var express = require("express")
var app = express()
app.use(express.static('static'))
app.use(express.json());
app.use(express.urlencoded({extended:false}));
//返回客户端数据
var arr=[
    {email:'1008611110@qq.com',name:'老马',phone:'110120119',pass:'123456',ingroup:'创意组',isadmin:true,status:true},
    {email:'1008611110@qq.com',name:'老马',phone:'110120119',pass:'123456',ingroup:'创意组',isadmin:true,status:true},
    {email:'1008611110@qq.com',name:'老马',phone:'110120119',pass:'123456',ingroup:'创意组',isadmin:true,status:true},
]
app.get('/user/list',(req,res)=>{
    var {page,count}=req.query;
    var newarr = arr.slice((page-1)*count,page*count);
    res.send( { code:200, msg:'请求成功!',list: newarr } );
})

app.get('/user/search',(req,res)=>{
    var {searchkey} = req,query;
    var newarr = arr.filter((item)=>{
        return new RegExp(searchkey).test(item.name)
    })
    res.send({code:200,msg:'查询成功!',list:newarr})
})
app.listen(8080,()=>{
    console.log('服务端运行在:ttp://localhost:8080');
})

